﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Hanhud.Data;

namespace Hanhud
{
    public class CProject : IXmlSerializable
    {
        #region Properties
        private string _projectID = null;
        public string ProjectID { get { return _projectID; } protected set { _projectID = value; } }

        private DateTime _addedDate = DateTime.Now;
        public DateTime AddedDate { get { return _addedDate; } protected set { _addedDate = value; } }

        private string _name = null;
        public string Name { get { return _name; } set { _name = value; } }

        private string _title = null;
        public string Title { get { return _title; } set { _title = value; } }

        private float _totalSquare = -1;
        public float TotalSquare { get { return _totalSquare; } set { _totalSquare = value; } }

        private DateTime _launchDate = DateTime.Now;
        public DateTime LaunchDate { get { return _launchDate; } set { _launchDate = value; } }

        private DateTime _finishDate = DateTime.Now;
        public DateTime FinishDate { get { return _finishDate; } set { _finishDate = value; } }

        private string _constructionUnit = null;
        public string ConstructionUnit { get { return _constructionUnit; } set { _constructionUnit = value; } }

        private string _constructionSupervisionUnit = null;
        public string ConstructionSupervisionUnit { get { return _constructionSupervisionUnit; } set { _constructionSupervisionUnit = value; } }

        private string _designingUnit = null;
        public string DesigningUnit { get { return _designingUnit; } set { _designingUnit = value; } }

        private string _investor = null;
        public string Investor { get { return _investor; } set { _investor = value; } }

        private CLocation _location = null;
        public CLocation Location { get { return _location; } set { _location = value; } }

        private EProjectType _projectType = EProjectType.Project;
        public EProjectType ProjectType { get { return _projectType; } set { _projectType = value; } }

        private List<CProjectDescription> _descriptions = null;
        public List<CProjectDescription> Descriptions
        {
            get
            {
                if (_descriptions == null)
                {
                    _descriptions = new List<CProjectDescription>();
                }
                return _descriptions;
            }
        }
        #endregion

        #region Constructors
        public CProject()
        {

        }

        public CProject(string projectID)
        {
        }

        public CProject(string projectID, DateTime addedDate, EProjectType projectType,
            int locationID, string lName, string lFullName, string lTitle, int provinceCode, int districtCode, int communeCode,
            string name, string title, float totalSquare, DateTime launchDate, DateTime finishDate,
            string constructionUnit, string constructionSupervisionUnit, string designingUnit, string investor)
        {
            this.ProjectID = projectID;
            this.AddedDate = addedDate;
            this.ProjectType = projectType;
            this.Location = new CLocation(locationID, lName, lFullName, lTitle, provinceCode, districtCode, communeCode);
            this.Name = name;
            this.Title = title;
            this.TotalSquare = totalSquare;
            this.LaunchDate = launchDate;
            this.FinishDate = finishDate;
            this.ConstructionUnit = constructionUnit;
            this.ConstructionSupervisionUnit = constructionSupervisionUnit;
            this.DesigningUnit = designingUnit;
            this.Investor = investor;
        } 
        #endregion

        #region Public methods
        public bool Update()
        {
            bool success = false;


            return success;
        }

        public bool Delete()
        {
            bool success = false;

            return success;
        }

        public bool UpdateDescriptions()
        {
            bool success = false;

            return success;
        } 
        #endregion

        #region Public static methods
        public static CProject GetProjectInfo(string projectID)
        {
            return null;
        }

        public static ProjectCollection GetProjectList()
        {
            throw new NotImplementedException();
        } 
        #endregion

        #region Xml serializable
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            throw new NotImplementedException();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            throw new NotImplementedException();
        } 
        #endregion
    }

    public class CProjectDescription
    {
        private int _projectDescriptionID = -1;
        public int ProjectDescriptionID { get { return _projectDescriptionID; } private set { _projectDescriptionID = value; } }

        private string _name = null;
        public string Name { get { return _name; } set { _name = value; } }

        private string _body = null;
        public string Body {
            get
            {
                if (string.IsNullOrEmpty(_body))
                    _body = GetDescriptionBody(this.ProjectDescriptionID);
                return _body;
            }
            set
            {
                _body = value;
            }
        }

        public CProjectDescription(int projectDescriptionID)
        {
            this.ProjectDescriptionID = projectDescriptionID;
        }

        public CProjectDescription(int projectDescriptionID, string name, string body)
        {
            this.ProjectDescriptionID = projectDescriptionID;
            this.Name = name;
            this.Body = body;
        }

        public static string GetDescriptionBody(int projectDescriptionID)
        {
            return null;
        }
    }

    public class PBound
    {
        
    }

    public class ProjectCollection : List<CProject>, IXmlSerializable
    {
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            throw new NotImplementedException();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("projectCollection");
            foreach (CProject proj in this)
            {
                proj.WriteXml(writer);
            }
            writer.WriteEndElement();
        }
    }
}
